<template>
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script scoped>
import BScroll from 'better-scroll'
// import BScroll from "@better-scroll/core";
// import PullUp from '@better-scroll/pull-up';
// import PullDown from "@better-scroll/pull-down";
// BScroll.use(PullDown);
// BScroll.use(PullUp);
// import BScroll from '@better-scroll/core'
export default {
  name:"Scroll",
  props:{
    probeType:{
      type:Number,
      default:0
    }
  },
  // 上拉加载
  pullUpLoad:{
    type:Boolean,
    default:false
  },
  data(){
    return {
      scroll:null
    }
  },
  mounted() {
     // 1.创建Bscroll对象
    this.scroll = new BScroll(this.$refs.wrapper,{
      scrollY:true,
      pullUpLoad: true,
      //  wheel: true,
      //  scrollbar: true,  
      /* pullDownRefresh:{
        threshold:50,//触发pullingDown事件的位置
        stop:0//下拉回弹后停留的位置
    }, */
      click:true,
      observeDOM:true,
      mouseWheel:true,
      probeType:this.probeType,
      //新版修复滚动区域bug
      observeDom:true,
      observeImage: true
      })
      
      // 2.监听滚动的位置
      this.scroll.on('scroll',(position) => {
        // console.log(position);
        this.$emit('scroll',position)
      })
      // 3.监听上拉事件
      this.scroll.on('pullingUp',() => {
        this.$emit('pullingUp')
        // console.log('加载更多');
      })
    /* setTimeout(() => {
       
    }, 2000); */
     
  },
  methods: {
    scrollTo(x,y,time=300){
      this.scroll && this.scroll.scrollTo(x,y,time)
  },
  finishPullUp(){
    this.scroll && this.scroll.finishPullUp()
  },
  refresh(){
      //console.log('dasdasd')
       this.scroll && this.scroll.refresh();
    },
  getScrollY(){
      return this.scroll ? this.scroll.y : 0;
    }
   }
}

</script>

<style>

</style>